Imports System.Data.SqlClient
Imports System.Drawing
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraEditors
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.UI
Imports DevExpress.XtraEditors.Repository

'--- Created Date On : 20-Sep-2010 (Gyana)

Public Class frmInvNurseNotes
    Dim mstrMode As String
    Public blnAdd As Boolean, blnEdit As Boolean, blnDelete As Boolean, blnLocked As Boolean
    Dim mlngRecordID As Long
    Dim blnUnload As Boolean
    Dim mblnChanged As Boolean
    Dim mblnActivate As Boolean
    Dim mblnExpanded As Boolean = False
    Dim mblnAutoSize As Boolean = True
    Dim gridView1 As Views.Grid.GridView
    Dim mblnCancelDisplay As Boolean
    Public mblnFrmOutside As Boolean = False
    Public mstrMenuList(17)() As String    'Keeps menu details (Jagged Arrays)


    'Private Sub initializeMenu()
    '    Try
    '        'Middle -1 Group
    '        'Middle -2 Locked

    '        'Last -1 Checked

    '        mstrMenuList(0) = New String() {"Main", 1, 0, "Main"}

    '        mstrMenuList(1) = New String() {"First Name", 2, 1, "A.FirstName"}
    '        mstrMenuList(2) = New String() {"Last Name", 2, 1, "A.LastName"}
    '        mstrMenuList(3) = New String() {"Speciality", 2, 1, "A.Speciality"}
    '        mstrMenuList(4) = New String() {"Address1", 2, 1, "A.Address1"}
    '        mstrMenuList(5) = New String() {"Address2", 2, 1, "A.Address2"}
    '        mstrMenuList(6) = New String() {"Town", 2, 1, "A.Town"}
    '        mstrMenuList(7) = New String() {"Parish", 0, 1, "A.Parish"}
    '        mstrMenuList(8) = New String() {"Country", 0, 1, "A.Country"}
    '        mstrMenuList(9) = New String() {"Post Code", 0, 1, "A.PostCode"}
    '        mstrMenuList(10) = New String() {"Phone1", 0, 1, "A.OfficePhone1"}
    '        mstrMenuList(11) = New String() {"Phone2", 0, 1, "A.OfficePhone2"}
    '        mstrMenuList(12) = New String() {"Phone3", 0, 1, "A.OfficePhone3"}
    '        mstrMenuList(13) = New String() {"Home Phone", 0, 1, "A.HomePhone"}
    '        mstrMenuList(14) = New String() {"Fax", 0, 1, "A.Fax"}
    '        mstrMenuList(15) = New String() {"Email", 0, 1, "A.Email"}
    '        mstrMenuList(16) = New String() {"Office Hours", 0, 1, "A.OfficeHours"}

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Sub frmSpecialist_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    '    Try
    '        If mblnActivate = True Then
    '            mblnActivate = False

    '            pbRecords.Visible = True
    '            pbRecords.BringToFront()
    '            Application.DoEvents()
    '            pbRecords.Position = 20

    '            'Fill speciality combo
    '            Call PopulateLookupDX(lkSpecility, "Speciality", "SpecialityId", "LtblSpeciality", "SpecialityId,Speciality", , "Speciality")
    '            'Fill Town combo
    '            Call PopulateLookupDX(lkTown, "Town", "TownId", "LtblTown", "TownId,Town", , "Town")
    '            'Fill Parish combo
    '            Call PopulateLookupDX(lkParish, "Parish", "ParishId", "LtblParish", "ParishId,Parish", , "Parish")
    '            'Fill Country combo
    '            Call PopulateLookupDX(lkCountry, "Country", "CountryId", "LtblCountry", "CountryId,Country", , "Country")

    '            Call PopulateData()
    '            pbRecords.Position = 100
    '            pbRecords.Visible = False
    '            grdRecords.Focus()
    '            If mblnFrmOutside = True Then
    '                btnAdd_Click(Nothing, Nothing)
    '            End If
    '        End If

    '    Catch ex As Exception
    '        pbRecords.Visible = False
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Sub frmSpecialist_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    '    Try

    '        Dim intUnload As DialogResult

    '        If mblnChanged = True And mstrMode <> "" Then
    '            intUnload = MessageBox.Show("You have not saved your changes to the record. Do you want to save your changes now?", gstrMessage, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
    '            If intUnload = Windows.Forms.DialogResult.Cancel Then
    '                e.Cancel = True : Exit Sub
    '            ElseIf intUnload = Windows.Forms.DialogResult.Yes Then
    '                blnUnload = True
    '                If blnSaveRecords() = False Then
    '                    e.Cancel = True
    '                    blnUnload = False
    '                    Exit Sub
    '                End If
    '                mblnChanged = False
    '            End If
    '        End If
    '        blnUnload = False

    '    Catch ex As Exception
    '        blnUnload = False
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Sub frmSpecialist_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    '    mblnCancelDisplay = True
    '    If blnKeyTrap(e.KeyCode, Me, True, grdRecords) = True Then mblnCancelDisplay = False : Exit Sub
    '    mblnCancelDisplay = False

    '    If e.KeyCode = Keys.F5 Then
    '        gdvRecords_FocusedRowChanged(Nothing, Nothing)
    '    End If

    '    pbRecords.Visible = False
    'End Sub

    'Private Sub frmSpecialist_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    '    Try

    '        Call SetImageControl(Me)
    '        Me.Icon = System.Drawing.Icon.FromHandle(CType(mdiMain.imgFormIcons.Images(2), Bitmap).GetHicon())
    '        Call btnExpand_Click(Me, e)
    '        Call GetAccessPermission(Me, "frmSpecialist")
    '        Call initializeMenu()
    '        Call setPBRecords(Me, pbRecords)
    '        mblnActivate = True
    '        mblnChanged = False

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Public Sub PopulateData()
    '    Dim dsRecords As New DataSet   'For populating data in XtraGrid
    '    Dim strQuery As String = ""
    '    Dim strTemp As String = ""
    '    Dim intCtr As Int16

    '    Try
    '        pbRecords.Position = 40 : Application.DoEvents()

    '        For intCtr = 0 To mstrMenuList.GetUpperBound(0) - 1
    '            If mstrMenuList(intCtr)(1) <> 1 And mstrMenuList(intCtr)(2) <> 0 Then
    '                strTemp = mstrMenuList(intCtr)(3)
    '                strQuery = strQuery & "," & strTemp & " [" & mstrMenuList(intCtr)(0) & "]"
    '            End If
    '        Next

    '        strQuery = "select A.DoctorId [record_id]" & strQuery & " From vwSpecialistDetails A Order By A.Firstname "

    '        dsRecords = FillDataSet(strQuery)
    '        'Bind the grid control to the data source
    '        gdvRecords.Columns.Clear()

    '        With grdRecords
    '            .BeginUpdate()
    '            .DataSource = dsRecords.Tables(0)
    '            .EndUpdate()
    '            .ForceInitialize()
    '        End With

    '        With gdvRecords
    '            'Primary Key Field
    '            .Columns("record_id").Visible = False
    '            .Columns("record_id").OptionsColumn.ShowInCustomizationForm = False
    '            .ExpandAllGroups()
    '            .BestFitColumns()
    '        End With

    '        dsRecords.Dispose()
    '        pbRecords.Position = 80 : Application.DoEvents()

    '        'To set row count
    '        Call gdvRecords_ColumnFilterChanged(Nothing, Nothing)

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Public Sub btnExpand_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExpand.Click
    '    If mblnExpanded = True Then
    '        mblnExpanded = False
    '        btnExpand.Image = mdiMain.imgEditIcons.Images(0)
    '        grdRecords.Width = 197
    '        Call btnCancel_Click(Nothing, Nothing)
    '    Else
    '        mblnExpanded = True
    '        btnExpand.Image = mdiMain.imgEditIcons.Images(1)
    '        grdRecords.Width = 737 : grdRecords.BringToFront()
    '        If gdvRecords.RowCount > 0 Then mlngRecordID = lngGetSelectID(gdvRecords, "record_id")
    '    End If

    '    gdvRecords.OptionsView.ColumnAutoWidth = False
    '    grdRecords.Focus()
    'End Sub

    'Private Sub DisplayData()
    '    'Display data in form fields.
    '    Dim dsTemp As DataSet
    '    Try

    '        dsTemp = FillDataSet("select * from tblSpecialists where DoctorId=" & mlngRecordID)

    '        With dsTemp.Tables(0)
    '            If .Rows.Count > 0 Then
    '                txtFirstName.Text = Trim(.Rows(0).Item("FirstName") & "")
    '                txtLastName.Text = Trim(.Rows(0).Item("LastName") & "")
    '                lkSpecility.EditValue = .Rows(0).Item("SpecialityId")
    '                txtAddress1.Text = Trim(.Rows(0).Item("Address1") & "")
    '                txtAddress2.Text = Trim(.Rows(0).Item("Address2") & "")
    '                lkTown.EditValue = .Rows(0).Item("TownId")
    '                lkParish.EditValue = .Rows(0).Item("ParishId")
    '                txtPhone1.Text = Trim(.Rows(0).Item("OfficePhone1") & "")
    '                txtPhone2.Text = Trim(.Rows(0).Item("OfficePhone2") & "")
    '                txtPhone3.Text = Trim(.Rows(0).Item("OfficePhone3") & "")
    '                txtFax.Text = Trim(.Rows(0).Item("Fax") & "")
    '                txtHomePhone.Text = Trim(.Rows(0).Item("HomePhone") & "")
    '                txtOfficeHours.Text = Trim(.Rows(0).Item("OfficeHours") & "")
    '                txtZipCode.Text = Trim(.Rows(0).Item("PostCode") & "")
    '                lkCountry.EditValue = Trim(.Rows(0).Item("CountryId") & "")
    '                txtEmail.Text = Trim(.Rows(0).Item("Email") & "")
    '            End If
    '        End With

    '        dsTemp.Dispose()

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Public Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    '    Call EnableDisableControls(True)

    '    If mstrMode = "Add" Then
    '        If gdvRecords.RowCount > 0 Then
    '            mlngRecordID = lngGetSelectID(gdvRecords, "record_id")
    '            DisplayData()
    '        Else
    '            ClearControls()
    '            btnEdit.Enabled = False : btnDelete.Enabled = False : btnPreview.Enabled = False
    '        End If
    '    Else
    '        If gdvRecords.RowCount = 0 Then
    '            ClearControls()
    '            btnEdit.Enabled = False : btnDelete.Enabled = False : btnPreview.Enabled = False
    '        Else
    '            DisplayData()
    '        End If
    '    End If

    '    Me.Text = "Specialist Details"
    '    mstrMode = ""
    '    mblnChanged = False
    'End Sub

    'Private Sub EnableDisableControls(ByVal blnEnable As Boolean)
    '    If blnAdd = True Then btnAdd.Enabled = blnEnable
    '    If blnEdit = True Then btnEdit.Enabled = blnEnable
    '    If blnDelete = True Then btnDelete.Enabled = blnEnable

    '    btnSave.Enabled = Not (blnEnable) : btnCancel.Enabled = Not (blnEnable)

    '    grbControls.Enabled = Not (blnEnable)
    'End Sub

    'Private Sub gdvRecords_ColumnFilterChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gdvRecords.ColumnFilterChanged
    '    gdvRecords.Columns(1).SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Count, "Total {0} Record(s)")

    '    Dim lngTemp As Long = lngGetSelectID(gdvRecords, "record_id")
    '    If mlngRecordID <> lngTemp Or btnCancel.Enabled = True Then
    '        gdvRecords_FocusedRowChanged(Nothing, Nothing)
    '    End If
    'End Sub

    'Private Sub gdvRecords_CustomDrawRowIndicator(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles gdvRecords.CustomDrawRowIndicator
    '    SetRowIndicator(e)
    'End Sub

    'Private Sub gdvRecords_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles gdvRecords.DoubleClick
    '    If btnEdit.Enabled = True Then
    '        Call btnEdit_Click(Nothing, Nothing)
    '    End If
    'End Sub

    'Private Sub gdvRecords_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles gdvRecords.FocusedRowChanged
    '    Try
    '        If mblnCancelDisplay = True Then Exit Sub

    '        mlngRecordID = lngGetSelectID(gdvRecords, "record_id")

    '        If gdvRecords.RowCount > 0 Then
    '            btnEdit.Enabled = blnEdit : btnDelete.Enabled = blnDelete
    '            btnPreview.Enabled = True
    '        Else
    '            ClearControls()
    '            btnEdit.Enabled = False : btnDelete.Enabled = False : btnPreview.Enabled = False
    '        End If
    '        btnAdd.Enabled = blnAdd

    '        If mlngRecordID = 0 Then Exit Sub

    '        If mblnExpanded = True Then Exit Sub

    '        Call btnCancel_Click(Nothing, Nothing)

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Sub gdvRecords_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles gdvRecords.GotFocus
    '    If btnCancel.Enabled = True And Me.Visible = True Then Call btnCancel_Click(Nothing, Nothing)
    'End Sub

    'Private Sub gdvRecords_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles gdvRecords.KeyDown
    '    Try

    '        If e.KeyCode = Keys.Delete And btnDelete.Enabled = True Then
    '            Call btnDelete_Click(Nothing, Nothing)
    '        ElseIf e.KeyCode = Keys.Return And btnDelete.Enabled = True Then
    '            Call gdvRecords_DoubleClick(Nothing, Nothing)
    '        ElseIf e.KeyCode = Keys.Escape Then
    '            Call btnClose_Click(Nothing, Nothing)
    '        End If

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
    '    'If mblnActivate = False Then
    '    '    If mblnExpanded = False Then btnExpand_Click(Nothing, Nothing) Else Me.Close()
    '    'End If
    '    Me.Close()
    'End Sub

    'Public Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    '    Try
    '        If mblnExpanded = True Then btnExpand_Click(Nothing, Nothing)
    '        Call EnableDisableControls(False)
    '        Call ClearControls()
    '        mstrMode = "Add"
    '        mlngRecordID = 0
    '        Me.Text = "Specialist Details [Add]"
    '        txtFirstName.Focus()
    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Function IsValidEntry() As Boolean
    '    'Here check valid entry of fields
    '    Dim strMsg As String = ""
    '    IsValidEntry = False

    '    If IsDBNullOrNothing(txtFirstName.Text) Then
    '        strMsg = "Please enter First Name"
    '        txtFirstName.Focus()
    '    ElseIf IsDBNullOrNothing(txtLastName.Text) Then
    '        strMsg = "Please enter Last Name"
    '        txtLastName.Focus()
    '    ElseIf IsDBNullOrNothing(lkTown.EditValue) Then
    '        strMsg = "Please select Town"
    '        lkTown.Focus()
    '    ElseIf IsDBNullOrNothing(lkParish.EditValue) Then
    '        strMsg = "Please select Parish"
    '        lkParish.Focus()
    '    ElseIf IsDBNullOrNothing(lkCountry.EditValue) Then
    '        strMsg = "Please select Country"
    '        lkCountry.Focus()
    '    ElseIf IsDBNullOrNothing(lkSpecility.EditValue) Then
    '        strMsg = "Please select Speciality"
    '        lkSpecility.Focus()
    '    End If

    '    If Trim(strMsg) <> "" Then
    '        IsValidEntry = False
    '        MessageBox.Show(strMsg, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '    Else
    '        IsValidEntry = True
    '    End If
    'End Function

    'Private Function blnSaveRecords() As Boolean
    '    Dim blnIsTransactionOpen As Boolean
    '    Dim strQuery As String
    '    Try
    '        blnSaveRecords = False

    '        If IsValidEntry() = False Then
    '            Exit Function
    '        End If



    '        If (blnUnload = False) Then
    '            If (MessageBox.Show("Are you sure to " & IIf(mstrMode = "Add", "add", "modify") & " this specialist", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.No) Then
    '                txtFirstName.Focus()
    '                Exit Function
    '            End If
    '        End If

    '        gtrnWebPlusMed = gconWebPlusMed.BeginTransaction
    '        blnIsTransactionOpen = True
    '        If (mstrMode = "Add") Then
    '            strQuery = "'" & Replace(Trim(txtLastName.Text), "'", "''") & "'"
    '            strQuery = strQuery & ",'" & Replace(Trim(txtFirstName.Text), "'", "''") & "'"
    '            If Not IsDBNullOrNothing(Val(lkSpecility.EditValue)) Then
    '                strQuery = strQuery & "," & Val(lkSpecility.EditValue)
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtAddress1.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtAddress1.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtAddress2.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtAddress2.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(lkTown.EditValue) Then
    '                strQuery = strQuery & "," & Val(lkTown.EditValue)
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(lkParish.EditValue) Then
    '                strQuery = strQuery & "," & Val(lkParish.EditValue)
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtPhone1.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtPhone1.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtPhone2.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtPhone2.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtPhone3.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtPhone3.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtFax.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtFax.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtHomePhone.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtHomePhone.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtOfficeHours.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtOfficeHours.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtZipCode.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtZipCode.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            strQuery = strQuery & "," & Val(lkCountry.EditValue)
    '            If Not IsDBNullOrNothing(txtEmail.Text) Then
    '                strQuery = strQuery & ",'" & Replace(Trim(txtEmail.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Null"
    '            End If
    '            InsertintoTable("tblSpecialists", strQuery)
    '        ElseIf (mstrMode = "Edit") Then
    '            strQuery = "Lastname='" & Replace(Trim(txtLastName.Text), "'", "''") & "'"
    '            strQuery = strQuery & ",Firstname='" & Replace(Trim(txtFirstName.Text), "'", "''") & "'"
    '            If Not IsDBNullOrNothing(Val(lkSpecility.EditValue)) Then
    '                strQuery = strQuery & ",SpecialityId=" & Val(lkSpecility.EditValue)
    '            Else
    '                strQuery = strQuery & ",SpecialityId=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtAddress1.Text) Then
    '                strQuery = strQuery & ",Address1='" & Replace(Trim(txtAddress1.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Address1=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtAddress2.Text) Then
    '                strQuery = strQuery & ",Address2='" & Replace(Trim(txtAddress2.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Address2=Null"
    '            End If
    '            If Not IsDBNullOrNothing(lkTown.EditValue) Then
    '                strQuery = strQuery & ",TownId=" & Val(lkTown.EditValue)
    '            Else
    '                strQuery = strQuery & ",TownId=Null"
    '            End If
    '            If Not IsDBNullOrNothing(lkParish.EditValue) Then
    '                strQuery = strQuery & ",ParishId=" & Val(lkParish.EditValue)
    '            Else
    '                strQuery = strQuery & ",ParishId=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtPhone1.Text) Then
    '                strQuery = strQuery & ",OfficePhone1='" & Replace(Trim(txtPhone1.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",OfficePhone1=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtPhone2.Text) Then
    '                strQuery = strQuery & ",OfficePhone2='" & Replace(Trim(txtPhone2.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",OfficePhone2=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtPhone3.Text) Then
    '                strQuery = strQuery & ",OfficePhone3='" & Replace(Trim(txtPhone3.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",OfficePhone3=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtFax.Text) Then
    '                strQuery = strQuery & ",Fax='" & Replace(Trim(txtFax.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Fax=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtHomePhone.Text) Then
    '                strQuery = strQuery & ",HomePhone='" & Replace(Trim(txtHomePhone.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",HomePhone=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtOfficeHours.Text) Then
    '                strQuery = strQuery & ",OfficeHours='" & Replace(Trim(txtOfficeHours.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",OfficeHours=Null"
    '            End If
    '            If Not IsDBNullOrNothing(txtZipCode.Text) Then
    '                strQuery = strQuery & ",PostCode='" & Replace(Trim(txtZipCode.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",PostCode=Null"
    '            End If
    '            strQuery = strQuery & ",CountryId=" & Val(lkCountry.EditValue)
    '            If Not IsDBNullOrNothing(txtEmail.Text) Then
    '                strQuery = strQuery & ",Email='" & Replace(Trim(txtEmail.Text), "'", "''") & "'"
    '            Else
    '                strQuery = strQuery & ",Email=Null"
    '            End If
    '            UpdateTable("tblSpecialists", strQuery, "DoctorId=" & mlngRecordID)
    '        End If

    '        blnSaveRecords = True

    '        gtrnWebPlusMed.Commit()
    '        blnIsTransactionOpen = False

    '    Catch ex As Exception
    '        If blnIsTransactionOpen = True Then
    '            gtrnWebPlusMed.Rollback()
    '        End If
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Function
    'Public Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
    '    Dim lngTemp As Long, lngRowID As Long
    '    Try
    '        If mblnChanged = False Then
    '            btnCancel_Click(Nothing, Nothing)
    '            Exit Sub
    '        End If

    '        If blnSaveRecords() = False Then Exit Sub
    '        If mstrMode = "Add" Then
    '            mlngRecordID = GetId("tblSpecialists")
    '        End If

    '        'If mblnChanged = False Then
    '        '    Call btnCancel_Click(Nothing, Nothing)
    '        'Else
    '        lngTemp = mlngRecordID

    '        pbRecords.Visible = True
    '        pbRecords.BringToFront()
    '        Application.DoEvents()
    '        pbRecords.Position = 20

    '        gdvRecords.OptionsSelection.EnableAppearanceFocusedRow = False
    '        gdvRecords.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None
    '        mblnCancelDisplay = True
    '        Call PopulateData()
    '        mblnCancelDisplay = False

    '        pbRecords.Position = 95
    '        If gdvRecords.RowCount > 0 Then
    '            lngRowID = LocateRowBySingleValue(grdRecords, lngTemp)
    '            gdvRecords.FocusedRowHandle = lngRowID
    '            If lngRowID = 0 Then gdvRecords_FocusedRowChanged(Nothing, Nothing)
    '        Else
    '            Call btnCancel_Click(Nothing, Nothing)
    '        End If
    '        gdvRecords.OptionsSelection.EnableAppearanceFocusedRow = True
    '        gdvRecords.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus

    '        pbRecords.Position = 100
    '        pbRecords.Visible = False
    '        'End If
    '        If mblnFrmOutside = True Then
    '            Me.Close()
    '        End If
    '    Catch ex As Exception
    '        pbRecords.Visible = False
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Public Sub btnPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPreview.Click
    '    ShowGridPreview(grdRecords, Me.Text)
    'End Sub

    'Public Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
    '    Try

    '        If mblnExpanded = True Then btnExpand_Click(Nothing, Nothing)

    '        Call EnableDisableControls(False)
    '        mblnChanged = False
    '        mstrMode = "Edit"
    '        Me.Text = "Specialist Details [Edit]"
    '        txtFirstName.Focus()
    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Sub gdvRecords_ShowGridMenu(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs) Handles gdvRecords.ShowGridMenu
    '    If e.MenuType = DevExpress.XtraGrid.Views.Grid.GridMenuType.Column Then
    '        Dim mainMenu As DevExpress.XtraGrid.Menu.ViewMenu = CType(e.Menu, DevExpress.XtraGrid.Menu.ViewMenu)
    '        Dim mainItem As New DevExpress.Utils.Menu.DXMenuItem("Column Auto Width", New EventHandler(AddressOf MainMenuItem))
    '        mainItem.BeginGroup = True
    '        mainItem.Tag = e.Menu
    '        mainMenu.Items.Add(mainItem)
    '        mainItem.Image = IIf(mblnAutoSize = True, mdiMain.imgEditIcons.Images(13), Nothing)
    '    End If
    'End Sub

    'Private Sub MainMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Dim Item As DevExpress.Utils.Menu.DXMenuItem = CType(sender, DevExpress.Utils.Menu.DXMenuItem)
    '    Dim menu As DevExpress.XtraGrid.Menu.GridViewMenu = CType(Item.Tag, DevExpress.XtraGrid.Menu.GridViewMenu)
    '    mblnAutoSize = Not (mblnAutoSize)
    '    gdvRecords.OptionsView.ColumnAutoWidth = (mblnAutoSize = True)
    '    If gdvRecords.OptionsView.ColumnAutoWidth = False Then gdvRecords.BestFitColumns()
    'End Sub

    'Private Sub txtFirstName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.GotFocus, txtLastName.GotFocus, txtAddress1.GotFocus, txtAddress2.GotFocus, txtEmail.GotFocus, txtFax.GotFocus, txtHomePhone.GotFocus, txtOfficeHours.GotFocus, txtPhone1.GotFocus, txtPhone2.GotFocus, txtPhone3.GotFocus, txtZipCode.GotFocus
    '    sender.SelectAll()
    'End Sub

    'Private Sub ClearControls()
    '    Try
    '        Call Clearfields(grbControls)

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Public Sub SetRowFromOutside(ByVal RecID As Long)
    '    Dim lngRowID As Long
    '    gdvRecords.OptionsSelection.EnableAppearanceFocusedRow = False
    '    gdvRecords.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None
    '    lngRowID = LocateRowBySingleValue(grdRecords, RecID)
    '    gdvRecords.FocusedRowHandle = lngRowID
    '    If lngRowID = 0 Then gdvRecords_FocusedRowChanged(Nothing, Nothing)
    '    gdvRecords.OptionsSelection.EnableAppearanceFocusedRow = True
    '    gdvRecords.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus
    'End Sub

    'Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    '    Dim blnTrnasaction As Boolean

    '    Try

    '        If MessageBox.Show("Are you sure you want to permanently delete this record", gstrMessage, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
    '            gtrnWebPlusMed = gconWebPlusMed.BeginTransaction
    '            blnTrnasaction = True
    '            Call DeleteFromTable("tblSpecialists", "DoctorId=" & mlngRecordID)
    '            gtrnWebPlusMed.Commit()
    '            blnTrnasaction = False
    '            MessageBox.Show("Record deleted", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Information)
    '            SendKeys.Send("{F5}")
    '        End If


    '    Catch ex As Exception
    '        If blnTrnasaction = True Then
    '            gtrnWebPlusMed.Rollback()
    '        End If
    '        MessageBox.Show("Record in use" & vbCrLf & "Cannot delete", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '             Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub

    'Private Sub lkTown_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles lkTown.ButtonClick
    '    If e.Button.Index = 1 Then
    '        Call PopulateLookupDX(lkTown, "Town", "TownId", "LtblTown", "TownId,Town", , "Town")
    '    End If
    'End Sub

    'Private Sub lkTown_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lkTown.EditValueChanged
    '    mblnChanged = True
    '    If Not IsDBNullOrNothing(lkTown.EditValue) Then
    '        lkParish.EditValue = CInt(Val(strRecordID("LtblTown", "ParishId", "TownId=" & Val(lkTown.EditValue))))
    '    End If
    'End Sub

    'Private Sub lkParish_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles lkParish.ButtonClick
    '    If e.Button.Index = 1 Then
    '        Call PopulateLookupDX(lkParish, "Parish", "ParishId", "LtblParish", "ParishId,Parish", , "Parish")
    '    End If
    'End Sub

    'Private Sub lkParish_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lkParish.EditValueChanged
    '    mblnChanged = True
    '    If Not IsDBNullOrNothing(lkParish.EditValue) Then
    '        lkCountry.EditValue = CInt(Val(strRecordID("LtblParish", "CountryId", "ParishId=" & Val(lkParish.EditValue))))
    '    End If
    'End Sub

    'Private Sub lkTown_ProcessNewValue(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs) Handles lkTown.ProcessNewValue
    '    If IsDBNullOrNothing(e.DisplayValue) = True Then Exit Sub
    '    If MessageBox.Show("This value is not present in the list. Do you want to add it now?", gstrMessage, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
    '        lkTown.EditValue = Nothing
    '        lkTown.Focus()
    '        Exit Sub
    '    End If
    '    With frmToolsLookUp
    '        .mblnFrmOtherForm = True
    '        .mstrLookUpValue = "LtblTown"
    '        .mintGrbId = 2
    '        .mstrItemName = e.DisplayValue
    '        .ShowDialog()
    '        Call PopulateLookupDX(lkTown, "Town", "TownId", "LtblTown", "TownId,Town", , "Town")
    '        If mlngLookUpId > 0 Then
    '            lkTown.EditValue = CInt(mlngLookUpId)
    '        Else
    '            lkTown.EditValue = Nothing
    '            lkTown.Focus()
    '        End If

    '        .Dispose()
    '        GC.Collect()
    '    End With
    '    mlngLookUpId = Nothing
    'End Sub

    'Private Sub lkSpecility_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles lkSpecility.ButtonClick
    '    If e.Button.Index = 1 Then
    '        'Fill speciality combo
    '        Call PopulateLookupDX(lkSpecility, "Speciality", "SpecialityId", "LtblSpeciality", "SpecialityId,Speciality", , "Speciality")
    '    End If
    'End Sub

    'Private Sub lkCountry_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles lkCountry.ButtonClick
    '    If e.Button.Index = 1 Then
    '        Call PopulateLookupDX(lkCountry, "Country", "CountryId", "LtblCountry", "CountryId,Country", , "Country")
    '    End If
    'End Sub

    'Private Sub txtFirstName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFirstName.TextChanged, txtAddress1.TextChanged, txtAddress2.TextChanged, txtEmail.TextChanged, txtFax.TextChanged, txtHomePhone.TextChanged, txtLastName.TextChanged, txtOfficeHours.TextChanged, txtPhone1.TextChanged, txtPhone2.TextChanged, txtPhone3.TextChanged, txtZipCode.TextChanged, lkCountry.EditValueChanged, lkParish.EditValueChanged, lkSpecility.EditValueChanged, lkTown.EditValueChanged
    '    mblnChanged = True
    'End Sub

    'Private Sub lkSpecility_ProcessNewValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs) Handles lkSpecility.ProcessNewValue
    '    If IsDBNullOrNothing(e.DisplayValue) = True Then Exit Sub
    '    If MessageBox.Show("This value is not present in the list. Do you want to add it now?", gstrMessage, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
    '        lkSpecility.EditValue = Nothing
    '        lkSpecility.Focus()
    '        Exit Sub
    '    End If
    '    With frmToolsLookUp
    '        .mblnFrmOtherForm = True
    '        .mintGrbId = 1
    '        .mstrLookUpValue = "LtblSpeciality"
    '        .mstrItemName = e.DisplayValue
    '        .ShowDialog()
    '        Call PopulateLookupDX(lkSpecility, "Speciality", "SpecialityId", "LtblSpeciality", "SpecialityId,Speciality", , "Speciality")
    '        If mlngLookUpId > 0 Then
    '            lkSpecility.EditValue = CInt(mlngLookUpId)
    '        Else
    '            lkSpecility.EditValue = Nothing
    '            lkSpecility.Focus()
    '        End If

    '        .Dispose()
    '        GC.Collect()
    '    End With
    '    mlngLookUpId = Nothing
    'End Sub


End Class
